<script type="text/javascript" src="javascript/ajax/prototype.js"></script>

<link rel="stylesheet" type="text/css" href="modules/IShopStore/pnjavascript/ddtabmenu/ddtabmenufiles/ddcolortabs_blue.css" />


<script type="text/javascript">
  function validateForm(form) {

    //Check category
    var category = document.getElementById("form_categories_name_");
    if (category.value == '') {
      alert("Please Enter Category name.");
      document.getElementById('error-category').innerHTML = " <FONT COLOR=\"#FF0000\">Enter Category name.</FONT>";
      category.focus();
      return false;
    }else{
      document.getElementById('error-category').innerHTML = "";
    }
    

    //Check category prefix
    var prefix = document.getElementById("form_categories_prefix_");
    var regexNum = /\d/;
    var regexLetter = /[a-zA-z]/;
    if (prefix.value == '') {
      alert("กรุณาใส่รหัสอักษรอังกฤษ");
      document.getElementById('form_categories_prefix_').innerHTML = " <FONT COLOR=\"#FF0000\">Enter Category prefix.</FONT>";
      prefix.focus();
      return false;
    }else{
      document.getElementById('error-category_prefix').innerHTML = "";
    }
    if (prefix.length > 2) {
      alert('กรุณาใส่รหัสอักษรอังกฤษ 2 ตัว');
      prefix.focus();
      return false;
    }
    if(regexNum.test(prefix.value) && !regexLetter.test(prefix.value)){
      alert('เฉพาะตัวอักษรอังกฤษเท่านั้น!!');
      prefix.focus();
      return false;
    }

    //Check image
    var image = document.getElementById("form_categories_image_");
    
    if (image.value == '') {
      alert("Please choose your category image.");
      document.getElementById('error-image').innerHTML = " <FONT COLOR=\"#FF0000\">Choose your category image.</FONT>";
      image.focus();
      return false;
    }else{
      document.getElementById('error-image').innerHTML = "";
    }
  }
</script>



<div id="ddtabs" class="ddcolortabs">
  <ul>
    <li><a href="<!--[pnmodurl modname='IShopStore' type='admin' func='page' ctrl='home']-->" rel="ct1"><span>หน้าหลัก</span></a></li>
    <li><a href="<!--[pnmodurl modname='IShopStore' type='admin' func='list' ctrl='Categories']-->" rel="ct1">
    <span>รายการหมวดหมู่</span></a></li>
  </ul>
</div>
<div class="ddcolortabsline">&nbsp;</div>
<!-- end tab menu -->


<fieldset>
<h4 class="innodocument-head">เพิ่ม / แก้ไข หมวดหมู่</h4>

<form id='form' class='form' action="<!--[pnmodurl modname='IShopStore' type='adminform' func='submit' ctrl='Categories']-->" method="post" enctype="multipart/form-data" onsubmit="return validateForm(this)">
<input type="hidden" name="form[id]" value="<!--[$_GET.id]-->" />

<TABLE width='50%' border="0" class="innoadvert-table">
<TR>
  <TD class='td-label'>ชื่อหมวดหมู่</TD>
  <TD>
    <TABLE>
    <TR>
      <TD><input id="form_categories_name_" type="text" name="form[name]" value="<!--[$form.name]-->" title="Please enter category name" class="required"  /><FONT SIZE="2" COLOR="#FF0000">&nbsp;*</FONT></TD>
      <TD><div id='error-category'></div></TD>
    </TR>
    </TABLE>
  </TD>
</TR>
<TR>
  <TD class='td-label'>รหัสอักษรหมวดหมู่&nbsp;<BR><FONT SIZE="1" COLOR="#FF0000">(ตัวอักษรภาษาอักกฤษเท่านั้น)</FONT></TD>
  <TD>
    <TABLE>
    <TR>
      <TD><input id="form_categories_prefix_" SIZE="2" maxlength="2" type="text" name="form[prefix]" value="<!--[$form.prefix]-->" title="Please enter category prefix" class="required"  /><FONT SIZE="2" COLOR="#FF0000">&nbsp;*</FONT></TD>
      <TD><div id='error-category_prefix'></div></TD>
    </TR>
    </TABLE>
  </TD>
</TR>
<TR>
  <TD></TD>
  <TD><!--[if $form.id]--><INPUT TYPE="submit" value='Update' name='Update' type="submit" ><!--[/if]-->
      <!--[if $form.id==null]--><INPUT TYPE="submit" value='Submit' name='Submit' type="submit" ><!--[/if]-->&nbsp;&nbsp;
      </TD>
</TR>
</TABLE>

</form>
</fieldset>